//
//  ＣommenFuctionViewController.m
//  DemoSecond
//
//  Created by yuzhuo on 16/7/19.
//  Copyright © 2016年 yuzhuo. All rights reserved.
//

#import "SelfInfoEditViewController.h"
#import "Constant.h"
#import "UIColor+Util.h"
#import "UserInfoEnity.h"
#import "SelfInfoEditTopCell.h"
#import "SelfInfoEditViewCell.h"

@interface SelfInfoEditViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView * tabView;
/** userInfoEntity */
@property (nonatomic,strong) UserInfoEnity *userdata;
/** data */
@property (nonatomic,strong) NSMutableArray<NSString *> *data;
@end

@implementation SelfInfoEditViewController


-(instancetype) init
{
    self = [super init];
    if(self){
        self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
        
        self.tabView.dataSource = self;
        self.tabView.delegate = self;
        [self initData];
    }
    return self;
}

-(void) initData{
    _userdata = [UserInfoEnity new];
    _data = [NSMutableArray new];
    _userdata.userName = @"傻颖弟";
    _userdata.avatar = [UIImage imageNamed:@"default_parents"];
    _userdata.job = @"射鸡湿";
    _userdata.addr = @"山西省临汾市";
    
    [_data addObject:@"姓名"];
    [_data addObject:@"职业"];
    [_data addObject:@"居住地"];

}

-(void) viewDidLoad
{
    
    self.view.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.tabView];
    self.tabView.frame = self.view.bounds;
    //    self.tabView.backgroundColor = [UIColor whiteColor];
    [self.tabView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];
    self.tabView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.title  = @"编辑";//设置顶部标题

}


-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count+1;
    
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}


-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if(indexPath.section == 0){
//        return 110;
//    }else{
//        return 50;
//    }
    return 110;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if(indexPath.section == 0){
        static NSString *cellID = @"topcellID";
        SelfInfoEditTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if(cell == nil){
            cell = [[SelfInfoEditTopCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        cell.data = self.userdata.avatar;
        
        return cell;
    }else{
        static NSString *cellID = @"cellID";
        SelfInfoEditViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if(cell == nil){
            cell = [[SelfInfoEditViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        if(indexPath.section < self.data.count+1){
            cell.title = self.data[indexPath.section-1];
        }

        switch (indexPath.section) {
            case 1:
                cell.name = self.userdata.userName;
                break;
                
            case 2:
                cell.name = self.userdata.job;
                break;
                
            case 3:
                cell.name = self.userdata.addr;
                break;
                
            default:
                break;
        }
        
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    //    CellDetailsViewController *detailview = [CellDetailsViewController new];
    //    detailview.cellEnity = self.arrayData[indexPath.row];
    //    NSLog(@"click row%ld",indexPath.row);
    //    [self.navigationController pushViewController:detailview animated:YES];
}

@end
